<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container" id="app">
    <div class="layuimini-main">

            <!--实际上是版本匹配后的事件处理-->
            <!--
        版本事件
	 客户端传参:	packageId, versionNo
		当版本正确
		    返回状态码 2
		当版本错误
		    找包号
                当找到包: 读取设置好的模式 , model:['link','text']
                    返回状态码0 链接-
                    返回状态码1 显示信息
                当找不到包: 发送通用文本
            -->
        <div id="eventList">
            <div class="version">大版本:
                <div class="layui-inline" >
                    <input type="text" class="layui-input" :value="versionNow" v-on:change="versionChange($event,'versionNow')">
                </div>
            </div>
            <br>
            <div class="version">PC热更新版本:
                <div class="layui-inline" >
                    <input type="text" class="layui-input" :value="hostVersion" v-on:change="versionChange($event,'hostVersion')">
                </div>
            </div>
            <br>
            <div class="version">安卓热更新版本:
                <div class="layui-inline" >
                    <input type="text" class="layui-input" :value="hostVersionAndriod" v-on:change="versionChange($event,'hostVersionAndriod')">
                </div>
            </div>
            <br>
            <div class="version">IOS热更新版本:
                <div class="layui-inline" >
                    <input type="text" class="layui-input" :value="hostVersionIos" v-on:change="versionChange($event,'hostVersionIos')">
                </div>
            </div>
            <br>
            <div class="all-message">全局文案:
                <div class="layui-inline" style="width: 500px;">
                    <input type="text" class="layui-input" :value="versionEventGlobalText" v-on:change="versionEventGlobalTextChange">
                </div>
            </div>
            <p>
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" v-on:click="versionEventAdd()" auth="versionEvent:add">添加</button>
            </p>
            <table class="layui-table">
                <thead>
                    <tr>
                        <th>渠道</th>
                        <th>包号</th>
                        <th>模式</th> <!--版本匹配不一致后事件处理-->
                        <th>链接</th>
                        <th>消息提示</th>
                        <th>备注</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="item in versionEventList">
                        <td>
                            {{item.channel.name}}
                        </td>
                        <td>
                            {{getVersionNoList(item.package_nos)}}
                        </td>
                        <td>
                            {{getModelName(item.model)}}
                        </td>
                        <td>
                            <p>andriod: {{item.andriod_url}}</p>
                            <p>ios: {{item.ios_url}}</p>
                            <p>pc: {{item.pc_url}}</p>
                        </td>
                        <td>
                            {{item.message}}
                        </td>
                        <td>
                            {{item.comment}}
                        </td>
                        <td>
                            <button class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" v-on:click="versionEventEdit(item.id)">
                                编辑
                            </button>
                            <button class="layui-btn layui-btn-xs layui-btn-danger" v-on:click="versionEventDel(item.id)">
                                删除
                            </button>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<style>
    .all-message,.version{
        line-height: 30px;
    }
</style>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/common.js?v=5" charset="utf-8"></script>
<script>
    var _this = this;
    var $;
    new Vue({
        el:"#app",
        data:{
            versionNow:'',
            hostVersion :'',
            hostVersionAndriod :'',
            hostVersionIos :'',
            versionEventGlobalText:'',
            versionEventList:[],
        },
        created(){
            _this = this
        },
        methods:{
            versionEventGlobalTextChange(e){
                var val = e.target.value;
                $.post('/admin/setting/setByName',{_method:"put",name:"versionEventGlobalText",val:val},function(res){
                    if (res.code===0){
                        layer.msg('success',{icon:1})
                    }
                })
            },
            versionChange(e,name){
                var val = e.target.value;
                $.post('/admin/setting/setByName',{_method:"put",name:name,val:val},function(res){
                    if (res.code===0){
                        layer.msg('success',{icon:1})
                    }
                })
            },
            versionEventAdd(){
                layer.open({
                    title: '添加',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['600px', '700px'],
                    content: 'form.html',
                });
            },
            getModelName(model){
                switch(parseInt(model)) {
                    case 0: return '显示链接'
                    case 1: return '消息提示'
                    case 2: return '全局文案'
                }
            },
            getVersionNoList(package_nos){
                var text = '';

                package_nos.forEach(package_no=>{
                    text += ',' + package_no
                })
                return text.substring(1)
            },
            versionEventEdit(id){
                layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['900px', '950px'],
                    content: 'form.html?id='+id,
                });
            },
            versionEventDel(id){
                layui.use(['form'], function () {
                    var  $ = layui.$;
                    var delPop = layer.confirm('确定要删除吗?', {icon: 3}, function () {
                        $.post('/admin/versionEvent/' + id, {_method: 'delete'}, function (res) {
                            if (res.code === 0) {
                                layer.msg('删除成功', {icon: 1, time: 500}, function () {
                                    table.reload('currentTableId');
                                })
                                table.reload()
                                layer.close(delPop)
                            } else {
                                layer.msg(res.msg, {icon: 2})
                            }
                        });
                    })
                })
            },
        },
        mounted(){
            layui.use(['form'], function () {
                $ = layui.$;
                $.get('/admin/versionEvent/list',{},function (res) {
                    if (res.code===0){
                        _this.versionEventList = res.data;
                    }
                })
                $.get('/admin/setting/getByName',{name:'versionEventGlobalText'},function(res){
                    _this.versionEventGlobalText = res.data.val
                })


                $.get('/admin/setting/getByName',{name:'versionNow'},function(res){
                    _this.versionNow = res.data.val
                })

                $.get('/admin/setting/getByName',{name:'hostVersion'},function(res){ //PC
                    _this.hostVersion = res.data.val
                })
                $.get('/admin/setting/getByName',{name:'hostVersionAndriod'},function(res){
                    _this.hostVersionAndriod = res.data.val
                })
                $.get('/admin/setting/getByName',{name:'hostVersionIos'},function(res){
                    _this.hostVersionIos = res.data.val
                })

            });
        }
    })

</script>
</body>
</html>